
namespace SIP.PN.FrontEnd.Code
{
    public class FuncionesJava
    {
        public static string BuildTagsScript(string script)
        {
            return "<script> " + script + " </script>";
        }

        public static string CerrarVentana(bool withScriptTags)
        {
            string result = "window.close();";
            if (withScriptTags)
                result = BuildTagsScript(result);
            return result;
        }

        public static string Alert(string mensaje, bool withScriptTags)
        {
            string result = "alert('" + mensaje + "');";
            if (withScriptTags)
                result = BuildTagsScript(result);
            return result;
        }

        public static string AlertAndClose(string mensaje, bool withScriptTags)
        {
            string result = "alert('" + mensaje + "'); window.close();";
            if (withScriptTags)
                result = BuildTagsScript(result);
            return result;
        }

        public static string Confirm(string mensaje)
        {
            string code = "javascript:return confirm('" + mensaje + "')";
            return code;
        }

        public static string OpenDialogModal(string url, int height, int width, bool resizable)
        {
            string Resizable = "No";
            string conector = "?";
            string exploter, morzilla;

            if (resizable)
            {
                Resizable = "Yes";
            }

            if (url.IndexOf(conector) > 0)
                conector = "&";

            exploter = "window.showModalDialog('" + url + conector + "Dialog=True','Dialog Box Arguments # 1','dialogHeight: " + height + "px; dialogWidth: " + width + "px; edge: Raised; center: Yes; resizable: " + Resizable + "; status: No; scrollbars: No;');";
            morzilla = "window.open('" + url + conector + "Dialog=True','','modal=YES,width=" + width + ",height=" + height + ",,left=200,top=250,scrollbars=NO'); ";

            return "javascript:if (window.showModalDialog) " + exploter + " else " + morzilla;
        }
    }
}
